*** The Bipolar Voter: On the Effect of Political Polarization on Voter Turnout
*** Replication Do-file
*** Empirical Analyses
*** 12.22.2016

** Empirical Analyses
* Table 1
cd "/Users/mmoral/Google Drive/SUNY Binghamton PhD/Miscellaneous/The Bipolar Voter/"
use "Replication Data.dta", clear 
global controls enepdis inc educ age female union idst strpartisan p_1-p_23

eststo m1: logit vote c.polv1perc##c.polinf2 $controls if ignorant0>=3 & ignorant1==0, robust
eststo m2: logit vote c.polv1difv2##c.polinf2 polv1 $controls, robust
eststo m3: logit vote c.polv1difv2##c.polinf2 polv1 polv1delta $controls, robust
esttab m1 m2 m3 using "table1.tex", tex replace b(%10.3f) se stats(ll N, labels("Log likelihood" "N") fmt(%10.3f %10.0f)) label starlevels(* 0.1 ** 0.05 *** 0.01) varlabels(_cons Constant) drop(p_*) addnote("Robust standard errors in parentheses. Two-tailed tests. Election fixed-effects are omitted from the table.") alignment(l) nonote nogaps nodepvars nonumbers compress noomit nobase mtitle("Model.1" "Model.2" "Model.3")

* Appendix B
qui logit vote c.polv1difv2##c.polinf2 polv1 $controls
eststo desc1: estpost tabstat vote polv1perc polv1difv2 polv1 polinf2 enepdis inc educ age female union idst strpartisan if e(sample), stats(min mean max sd N) columns(statistics)
qui logit vote c.polv1difv2##c.polinf2 polv1 polv1delta $controls, robust
eststo desc2: estpost tabstat vote polv1perc polv1difv2 polv1 polv1delta polinf2 enepdis inc educ age female union idst strpartisan if e(sample), stats(min mean max sd N) columns(statistics)
esttab desc1 using appendixb.tex, replace cells("min(fmt(2)) mean(fmt(2)) max(fmt(2)) sd(fmt(2)) count(fmt(0))") collabels("Min." "Mean" "Max." "Std.Dev." "N" ) noobs nonumber label title("Descriptive Statistics") longtable
esttab desc2 using appendixb.tex, append cells("min(fmt(2)) mean(fmt(2)) max(fmt(2)) sd(fmt(2)) count(fmt(0))") collabels("Min." "Mean" "Max." "Std.Dev." "N" ) noobs nonumber label title("Descriptive Statistics") longtable

* Appendix C
qui logit vote c.polv1difv2##c.polinf2 polv1 $controls, robust
tabstat polv1perc polv1difv2 polv1 polv1delta crepol wpsc wepdm estray if e(sample), by(pan) stats(mean sd) format(%10.2f)

* Appendix D
gen mix=1 if pan=="DEU2005" | pan=="DEU2009" | pan=="GRC2009"
eststo a1: logit vote c.polv1difv2##c.polinf2 polv1 $controls if mix!=1, robust
eststo a2: logit vote c.polv1difv2##c.polinf2 polv1 polv1delta $controls if mix!=1, robust
qui logit vote c.polv1difv3##c.polinf2 enepdis inc educ age female union idst strpartisan, robust
drop p_*
tab pan if e(sample), gen(p_)
drop p_10
eststo a3: logit vote c.polv1difv3##c.polinf2 polv1 $controls, robust
eststo a4: logit vote c.polv1difv3##c.polinf2 polv1 polv1delta $controls, robust
qui logit vote c.polv1difv2##c.polinf2 polv1 enepdis inc educ age female union idst strpartisan
drop p_*
tab pan if e(sample), gen(p_)
drop p_10
eststo a5: logit vote c.polv1difv2##c.educ polinf2 polv1 $controls, robust
eststo a6: logit vote c.polv1difv2##c.educ polinf2 polv1 polv1delta $controls, robust
eststo a7: melogit vote c.polv1difv2##c.polinf2 enepdis inc educ age female union idst strpartisan || pan: polv1, startgrid
eststo a8: melogit vote c.polv1difv2##c.polinf2 enepdis inc educ age female union idst strpartisan || pan: polv1 polv1delta, startgrid

esttab a1 a2 a3 a4 a5 a6 a7 a8 using "appendixd.tex", tex replace b(%10.3f) se stats(ll N, labels("Log likelihood" "N") fmt(%10.3f %10.0f)) label starlevels(* 0.1 **  0.05 *** 0.01) varlabels(_cons Constant) drop(p_*) addnote("Robust standard errors in parentheses. Two-tailed tests. Election fixed-effects are omitted from the table.") alignment(l) nonote nogaps nodepvars nonumbers compress noomit nobase mtitle("Model.A1" "Model.A2" "Model.A3" "Model.A4" "Model.A5" "Model.A6" "Model.A7" "Model.A8")

* Appendix E
eststo crepol: logit vote c.crepoldifv2##c.polinf2 crepol $controls, robust
foreach var of varlist wpsc wepdm estray {
eststo `var': logit vote c.polv1difv2##c.polinf2 `var' $controls, robust
}

esttab crepol wpsc wepdm estray using "appendixe.tex", tex replace b(%10.3f) se stats(ll N, labels("Log likelihood" "N") fmt(%10.3f %10.0f)) label starlevels(* 0.1 **  0.05 *** 0.01) varlabels(_cons Constant) drop (p_*) addnote("Robust standard errors in parentheses. Two-tailed tests. Election fixed-effects are omitted from the table.") alignment(l) nonote nogaps nodepvars nonumbers compress noomit nobase mtitle("Crepaz (1990)" "Dow (2011)" "Lachat(2008)" "E\&R (1994)")

** Figures
* Figure 1: Effects of Perceived and Actual Party Polarization on Turnout | Political Information (Model.2)
global controls enepdis inc educ age female union idst strpartisan
logit vote c.polv1difv2##c.polinf2 polv1 $controls p_1-p_22, robust
estat sum
sum polv1difv2 polinf2 polv1 if e(sample), detail
margins, at((median) _all (mean) enepdis inc educ idst polv1difv2=(-3.25(.25)4.25) polinf2=(-1.19017 .2249167 1.332054) polv1=(2.900811 3.325583 4.480503))
marginsplot, byop(rows(1) title("")) bydim(polv1,  elabel(1 "Low Party Polarization (10%)" 2 "Median Party Polarization"  3 "High Party Polarization (90%)")) ///
ciopts(recast(rspike) lwidth(thin)) ci1opts(lcolor(gs0)) ci2opts(lcolor(gs6)) ci3opts(lcolor(gs12)) ///
plotopts(msize(small) lpattern(dot)) plot1opts(mcolor(gs0)) plot2opts(mcolor(gs6)) plot3opts(mcolor(gs12)) ///
legend(order(4 "Politically Uninformed (10%)" 5 "Median Political Information" 6 "Politically Informed (90%)") symxsize(0)) ///
xtitle("Perceived Party Polarization (Difference from Actual Party Polarization)") ytitle("Pr(Turnout)") xlab(-3(1)4, nogrid) ylab(.6(.1)1)
graph export "Figure1.pdf", replace

* Figure 2: Effects of Perceived and $\Delta$ Party Polarization on Turnout | Political Information (Model.3)
logit vote c.polv1difv2##c.polinf2 polv1delta polv1 $controls p_2 p_4 p_6 p_7 p_13 p_15 p_17 p_19 p_20, robust
estat sum
sum polv1difv2 polinf2 polv1delta if e(sample), detail
margins, at((median) _all (mean) enepdis inc educ idst polv1 polv1difv2=(-3.25(.25)3.75) polinf2=(-1.19017 .2056841 1.332054) polv1delta=(-.6062191 -.040956 .4867804))
marginsplot, byop(rows(1) title("")) bydim(polv1delta,  elabel(1 "Low {&Delta} Party Polarization (10%)" 2 "Median {&Delta} Party Polarization"  3 "High {&Delta} Party Polarization (90%)")) ///
ciopts(recast(rspike) lcolor(black) lwidth(thin)) ci1opts(lcolor(gs0)) ci2opts(lcolor(gs6)) ci3opts(lcolor(gs12)) ///
plotopts(msize(small) lpattern(dot)) plot1opts(mcolor(gs0)) plot2opts(mcolor(gs6)) plot3opts(mcolor(gs12)) ///
legend(order(4 "Politically Uninformed (10%)" 5 "Median Political Information" 6 "Politically Informed (90%)") symxsize(0)) ///
xtitle("Perceived Party Polarization (Difference from Actual Party Polarization)") ytitle("Pr(Turnout)") xlab(-3(1)4, nogrid) ylab(.6(.1)1)
graph export "Figure2.pdf", replace

** In-text explanations
* Footnote#14
qui logit vote c.polv1difv2##c.polinf2 polv1 $controls p_1-p_22, robust
corr polv1difv2 polinf2 polv1 $controls if e(sample)

* Footnote#17
logit vote c.polv1perc##c.polinf2 $controls p_1-p_23 if ignorant0>=3 & ignorant1==0, robust
sum polv1perc polinf2 if e(sample), detail
margins, at((median) _all (mean) enepdis inc educ idst polv1perc=(0(.25)10) polinf2=(-1.19017 .2249167 1.332054))
marginsplot, ciopts(recast(rspike) lcolor(black) lwidth(thin)) ///
plot1opts(lpattern(dot) msize(small) mcolor(gs0)) plot2opts(lpattern(dot) msize(small) mcolor(gs6)) plot3opts(lpattern(dot) msize(small) mcolor(gs12)) ///
ci1opts(lcolor(gs0)) ci2opts(lcolor(gs6)) ci3opts(lcolor(gs12)) ///
legend(order(4 "Politically Uninformed (10%)" 5 "Median Political Information" 6 "Politically Informed (90%)") symxsize(0)) ///
xtitle("Perceived Polarization") ytitle("Pr(Turnout)") xlab(0(1)10, nogrid) ylab(.75(.05).95) scale(.75)
mat gen=r(at)
svmat gen
drop gen3-gen32
mat gep=r(table)'
svmat gep
drop gep2-gep4 gep7-gep9
gen d1=gep5-gep6[_n-2] in 1/123 if mod(_n,3)==0
sum d1 
list d1 gen1 if round(gen2*10)==-12 & d1<0
list d1 gen1 if round(gen2*10)==13 & d1<0

* Predicted probability of turnout in Figures 1 and 2
use "Replication Data.dta", clear
global controls enepdis inc educ age female union idst strpartisan 
logit vote c.polv1difv2##c.polinf2 polv1 $controls p_1-p_22, robust
margins, at((median) _all (mean) enepdis inc educ idst polv1difv2=(-3.25(.25)4.25) polinf2=(-1.19017 .2249167 1.332054) polv1=(2.900811 3.325583 4.480503))
mat gen=r(at)
svmat gen
drop gen4-gen32
mat gep=r(table)'
svmat gep
drop gep2-gep4 gep7-gep9

gen d1=gep5-gep6[_n-2] in 1/657 if mod(_n,3)==0
sum d1 
list d1 gen3 gen1 if round(gen2*10)==-12 & d1<0
list d1 gen3 gen1 if round(gen2*10)==13 & d1<0
sum polv1difv2 if e(sample) & polv1difv2>-1.75 & polv1difv2<1.25
disp `r(N)'/23220

sort gen3 gen1 gen2
gen d2=gep5-gep6[_n-2] in 1/657 if mod(_n,3)==0
sum d2
 
sort gen2 gen1 gen3
tabstat gep1 if gen1==-2 & round(gen2)==-1, stats(min max range)
tabstat gep1 if gen1==-2 & round(gen2)==1, stats(min max range)
tabstat gep1 if gen1==2 & round(gen2)==-1, stats(min max range)
tabstat gep1 if gen1==2 & round(gen2)==1, stats(min max range)

sort gen1 gen2 gen3
tabstat gep1 if gen3==gen3[1], by(gen2) stats(min max range)
tabstat gep1 if gen3==gen3[3], by(gen2) stats(min max range)

drop gen* gep* d1 d2
logit vote c.polv1difv2##c.polinf2 polv1delta polv1 $controls p_2 p_4 p_6 p_7 p_13 p_15 p_17 p_19 p_20, robust
margins, at((median) _all (mean) enepdis inc educ idst polv1 polv1difv2=(-3.25(.25)3.75) polinf2=(-1.19017 .2056841 1.332054) polv1delta=(-.6062191 -.040956 .4867804))
mat gen=r(at)
svmat gen
drop gen4-gen21
mat gep=r(table)'
svmat gep
drop gep2-gep4 gep7-gep9

gen d1=gep5-gep6[_n-2] in 1/270 if mod(_n,3)==0
sum d1
list d1 gen3 gen1 if round(gen2*10)==-12 & d1<0
list d1 gen3 gen1 if round(gen2*10)==13 & d1<0

sort gen3 gen1 gen2
gen d2=gep5-gep6[_n-2] in 1/270 if mod(_n,3)==0
sum d2
list d2 gen3 gen1 if round(gen2*10)==13 & d2<0
sum polv1difv2 if e(sample) & polv1difv2<=-1.5
disp `r(N)'/12731

sort gen2 gen1 gen3
tabstat gep1 if gen1==-2 & round(gen2)==-1, stats(min max range)
tabstat gep1 if gen1==-2 & round(gen2)==1, stats(min max range)
tabstat gep1 if gen1==2 & round(gen2)==-1, stats(min max range)
tabstat gep1 if gen1==2 & round(gen2)==1, stats(min max range)

sort gen1 gen2 gen3
tabstat gep1 if gen3==gen3[1], by(gen2) stats(min max range)
tabstat gep1 if gen3==gen3[3], by(gen2) stats(min max range)

* The substantive effect of actual and perceived party polarization on turnout (Model.1)
use "Replication Data.dta", clear
logit vote c.polv1perc##c.polinf2 $controls p_1-p_23 if ignorant0>=3 & ignorant1==0, robust
margins, dydx(polv1perc)
mat b=r(b)
sca marg=b[1,1]
sum polv1perc if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg

* The substantive effect of actual and perceived party polarization on turnout (Model.2)
global controls enepdis inc educ age female union idst strpartisan
logit vote c.polv1difv2##c.polinf2 polv1 $controls p_1-p_22, robust
margins, dydx(polv1)
mat b=r(b)
sca marg=b[1,1]
sum polv1 if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg

margins, dydx(polv1difv2)
mat b=r(b)
sca marg=b[1,1]
sum polv1difv2 if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg

* The substantive effect of actual and perceived party polarization on turnout (Model.3)
logit vote c.polv1difv2##c.polinf2 polv1delta polv1 $controls p_2 p_4 p_6 p_7 p_13 p_15 p_17 p_19 p_20, robust
margins, dydx(polv1)
mat b=r(b)
sca marg=b[1,1]
sum polv1 if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg 

margins, dydx(polv1difv2)
mat b=r(b)
sca marg=b[1,1]
sum polv1difv2 if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg 

margins, dydx(polv1delta)
mat b=r(b)
sca marg=b[1,1]
sum polv1delta if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg  

* Marginal effect of perceived party polarization on turnout | political information and party polarization (Model.2)
use "Replication Data.dta", clear
global controls enepdis inc educ age female union idst strpartisan 
logit vote c.polv1difv2##c.polinf2 polv1 $controls p_1-p_22, robust
estat sum 
mat stats=r(stats)
sum polv1 polinf2 if e(sample), detail

preserve
set seed 123456789
drawnorm b1-b34, n(10000) means(e(b)) cov(e(V)) clear
postutil clear
local p1=2.900811
local p2=3.325583
local p3=4.480503
local p4=3.591387
forval x=1/4 {
postfile mypost`x' pr0`x' lb0`x' ub0`x' pr1`x' lb1`x' ub1`x' difp`x' difl`x' difu`x' using sim`x', replace
forval i=-263/220 {
{
gen prob0`x'=1/(1+exp(-(b2*(`i'/100) + b4*`p`x'' + b5*stats[6,1] + b6*stats[7,1] + b7*stats[8,1] + b8*round(stats[9,1]) + b11*stats[12,1] + b12*stats[13,1] + b34)))
gen prob1`x'=1/(1+exp(-(b1 + b2*(`i'/100) + b3*(`i'/100) + b4*`p`x'' + b5*stats[6,1] + b6*stats[7,1] + b7*stats[8,1] + b8*round(stats[9,1]) + b11*stats[12,1] + b12*stats[13,1] + b34))) 
gen diff`x'=prob1-prob0
egen prob_hat0`x' =mean(prob0`x')
egen prob_hat1`x' =mean(prob1`x')
egen difp`x'  =mean(diff`x')
tempname pr0`x' lb0`x' ub0`x' pr1`x' lb1`x' ub1`x' difp`x' difl`x' difu`x'
_pctile prob0`x', p(2.5, 97.5) 
scalar `lb0`x'' = r(r1)
scalar `ub0`x'' = r(r2)  
_pctile prob1`x', p(2.5, 97.5)
scalar `lb1`x''= r(r1)
scalar `ub1`x''= r(r2)  
_pctile diff`x', p(2.5, 97.5)
scalar `difl`x''= r(r1)
scalar `difu`x''= r(r2)  
scalar `pr0`x''=prob_hat0`x'
scalar `pr1`x''=prob_hat1`x'
scalar `difp`x''=difp`x'
post mypost`x' (`pr0`x'') (`lb0`x'') (`ub0`x'') (`pr1`x'') (`lb1`x'') (`ub1`x'') (`difp`x'') (`difl`x'') (`difu`x'') 
}
drop prob0`x' prob1`x' diff`x' prob_hat0`x' prob_hat1`x' difp`x'
local i=`i'+1
disp _c(.) 
}
postclose mypost`x'
disp "Done!"
}

restore
merge using "sim1.dta" "sim2.dta" "sim3.dta" "sim4.dta" 
gen fpolinf2 = (_n/100)-2.64 in 1/484
sum difp* if round(fpolinf2*100)/100==0.14

* Comparison of the substantives effects of actual party polarization and effective number of parties variables (Model.2)
use "Replication Data.dta", clear
global controls enepdis inc educ age female union idst strpartisan
logit vote c.polv1difv2##c.polinf2 polv1 $controls p_1-p_22, robust
margins, dydx(polv1)
mat b=r(b)
sca marg=b[1,1]
qui sum polv1 if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg
margins, dydx(enepdis)
mat b=r(b)
sca marg=b[1,1]
qui sum enepdis if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg

* Comparison of the substantives effects of actual party polarization and effective number of parties variables (Model.3)
logit vote c.polv1difv2##c.polinf2 polv1delta polv1 $controls p_2 p_4 p_6 p_7 p_13 p_15 p_17 p_19 p_20, robust
margins, dydx(polv1)
mat b=r(b)
sca marg=b[1,1]
qui sum polv1 if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg 
margins, dydx(enepdis)
mat b=r(b)
sca marg=b[1,1]
qui sum enepdis if e(sample), detail
disp (`r(p75)'-`r(p25)')*marg 
